package jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

public class JDBCDemo3 {
    public static void main(String[] args){
        /*注册驱动*/

        /*创建连接*/
        try(Connection connection = DBUtil.getConnection();) {

            /*获取执行者对象*/
            Statement statement = connection.createStatement();

            String sql ="UPDATE userinfo\n" +
                    "SET password = '666666'\n" +
                    "WHERE username= '张三'";
            System.out.println(sql);
            /*执行sql*/
            int rows = statement.executeUpdate(sql);
            if(rows>0){
                System.out.println("修改成功");
            }else{
                System.out.println("修改失败");
            }
            /*关闭连接*/
            //Connection实现了AutoCloseable接口，自动关闭特性
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
